<template>
    <div class="mental-test" :style="backgroundStyle">
      <h1>心理健康测试单</h1>
      <button @click="openDialog">开始心理健康检查</button>
      <dialog v-if="dialogVisible" @click="closeDialog">
        <h2>心理健康检查</h2>
        <p>你是否经常焦虑？</p>
        <p>有没有注意力难以集中的情况？</p>
        <button @click="closeDialog">关闭</button>
      </dialog>
    </div>
  </template>
  
  <script setup>
  import { ref } from 'vue';
  
  const dialogVisible = ref(false);
  
  const openDialog = () => {
    dialogVisible.value = true;
  };
  
  const closeDialog = () => {
    dialogVisible.value = false;
  };
  
  const backgroundStyle = {
    backgroundImage: `url(${require('@/assets/img/xinli.png')})`, // 替换为你的图片路径
    backgroundSize: 'cover', // 使背景图片覆盖整个容器
    backgroundPosition: 'center', // 使背景图片居中
    width: '100%', // 设置宽度为100%
    height: '100%', // 设置高度为100%
    position: 'absolute', // 确保背景图片覆盖整个视口
    top: 0,
    left: 0
  };
  </script>
  
  <style scoped>
  .mental-test {
    text-align: center;
  }
  
  dialog {
    border: 1px solid #ccc;
    border-radius: 8px;
    padding: 20px;
    background-color: #f9f9f9;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  }
  
  button {
    margin-top: 20px;
    padding: 10px 20px;
    font-size: 16px;
    cursor: pointer;
  }
  </style>
  